<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>测试$.ajax()</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#btnId").click(function () {
                $.ajax({
                    async:false,
                    url:"${pageContext.request.contextPath}/TestAjaxServlet",
                    type:"POST",
                    // data:"username=admin&password=123456",
                    data:{username:"张三",password:123},
                    dataType:"text",
                    success:function (obj) {
                        alert(obj);
                    }
                });
                alert(123);

            });
        });
    </script>
</head>
<body>
<input type="text">
<input type="button" value="点击" id="btnId">
</body>
</html>
